package com.hr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hr.entity.HumanFile;
import com.hr.mapper.HumanFileMapper;
import com.hr.service.HumanFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HumanFileServiceImpl implements HumanFileService {
    @Autowired
    private HumanFileMapper humanFileMapper;

    @Override
    public Page<HumanFile> queryList(Page<HumanFile> page) {
//        List<HumanFile> list = humanFileMapper.selectList(new QueryWrapper<HumanFile>());
//        //分页参数
//        Page<HumanFile> page = new Page<HumanFile>();
//        //当前 页码
//        page.setCurrent(2);
//        //每页记录数
//        page.setSize(5);
        //查询条件
        QueryWrapper<HumanFile> queryWrapper = new QueryWrapper<HumanFile>();

        page = humanFileMapper.selectPage(page, queryWrapper);
        System.out.println(page);
        return page;
    }

    @Override
    public boolean save(HumanFile humanFile) {
        int rows = 0;
        if(humanFile.getHufid() == null){
            rows = humanFileMapper.insert(humanFile);
        }else{
            rows = humanFileMapper.updateById(humanFile);
        }
        return rows > 0;
    }

    @Override
    public boolean delete(Integer hufid) {
        int i = humanFileMapper.deleteById(hufid);
        return i > 0;
    }

    @Override
    public HumanFile queryById(Integer hufid) {

        HumanFile humanFile = humanFileMapper.selectById(hufid);
        return humanFile;
    }
}
